﻿using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Serialization;

namespace MediaBrowserSL.DAL.Contexts
{
    /// <summary>
    /// Exception prock
    /// </summary>
    [Serializable]
    public class SqlException : System.Exception
    {
        public SqlException()
            : base()
        {
            // 
        }

        public SqlException(string msg)
            : base(msg)
        {
            //
        }

        public SqlException(string msg, System.Exception innerEx) :
            base(msg, innerEx)
        {
            // 
        }

        protected SqlException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            // Implement type-specific serialization constructor logic.
        }

        public SqlException(string prock, string parameter, System.Exception inner)
        {
            //get name method
            StackTrace stackTrace = new StackTrace();
            StackFrame stackFrame = stackTrace.GetFrame(1);
            MethodBase methodBase = stackFrame.GetMethod();

            System.Data.Common.DbException objectData = (System.Data.Common.DbException)inner.GetBaseException();
            string message = "\r 1 - Class  : " + methodBase.DeclaringType.FullName +
                             "\r 2 - Member : " + methodBase.Name +
                             "\r 3 - Stored procedure : " + prock +
                             "\r 4 - Parameters : " + parameter +
                             "\r 5 - SQL error :  " + objectData.Message;
        }
    }
}
